package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 标准答案实体类
 * 对应数据库表：fill_standard_answer
 *
 * 根据B-02-03-05填空题管理子模块设计文档实现
 * 管理填空题的标准答案和等价答案，支持多答案配置和智能匹配。
 * 提供灵活的答案管理机制和相似度配置。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "fill_standard_answer")
@Comment("标准答案表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StandardAnswer {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 答案唯一标识符
     */
    @NotBlank(message = "答案ID不能为空")
    @Size(max = 50, message = "答案ID长度不能超过50个字符")
    @Column(name = "answer_id", nullable = false, length = 50, unique = true)
    private String answerId;

    /**
     * 关联的填空位置ID
     */
    @NotBlank(message = "填空位置ID不能为空")
    @Column(name = "position_id", nullable = false)
    private String positionId;

    /**
     * 关联的填空题ID
     */
    @NotBlank(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    private String questionId;

    /**
     * 答案内容
     */
    @NotBlank(message = "答案内容不能为空")
    @Column(name = "answer_text", nullable = false, columnDefinition = "TEXT")
    private String answerText;

    /**
     * 答案类型（EXACT-精确答案，EQUIVALENT-等价答案，ALTERNATIVE-备选答案，PARTIAL-部分答案）
     */
    @NotBlank(message = "答案类型不能为空")
    @Size(max = 30, message = "答案类型长度不能超过30个字符")
    @Column(name = "answer_type", nullable = false, length = 30)
    private String answerType;

    /**
     * 是否为主要答案
     */
    @NotNull(message = "主要答案标识不能为空")
    @Column(name = "is_primary", nullable = false)
    private Boolean isPrimary;

    /**
     * 答案优先级（数值越小优先级越高）
     */
    @NotNull(message = "答案优先级不能为空")
    @Column(name = "priority", nullable = false)
    private Integer priority;

    /**
     * 相似度阈值（0-1之间，用于模糊匹配）
     */
    @Column(name = "similarity_threshold", precision = 3, scale = 2)
    private Double similarityThreshold;

    /**
     * 权重因子（用于评分计算）
     */
    @Column(name = "weight_factor", precision = 3, scale = 2)
    private Double weightFactor;

    /**
     * 答案解释
     */
    @Column(name = "answer_explanation", columnDefinition = "TEXT")
    private String answerExplanation;

    /**
     * 答案提示
     */
    @Size(max = 200, message = "答案提示长度不能超过200个字符")
    @Column(name = "answer_hint", length = 200)
    private String answerHint;

    /**
     * 匹配模式（EXACT-精确匹配，FUZZY-模糊匹配，SEMANTIC-语义匹配，REGEX-正则匹配）
     */
    @Size(max = 20, message = "匹配模式长度不能超过20个字符")
    @Column(name = "match_mode", length = 20)
    private String matchMode;

    /**
     * 正则表达式（用于REGEX匹配模式）
     */
    @Size(max = 500, message = "正则表达式长度不能超过500个字符")
    @Column(name = "regex_pattern", length = 500)
    private String regexPattern;

    /**
     * 同义词列表（JSON格式，包含等价的同义词）
     */
    @Column(name = "synonyms", columnDefinition = "TEXT")
    private String synonyms;

    /**
     * 变体形式（JSON格式，包含答案的不同变体）
     */
    @Column(name = "answer_variants", columnDefinition = "TEXT")
    private String answerVariants;

    /**
     * 错误容忍度（允许的字符错误数）
     */
    @Column(name = "error_tolerance")
    private Integer errorTolerance;

    /**
     * 是否忽略大小写
     */
    @NotNull(message = "大小写设置不能为空")
    @Column(name = "ignore_case", nullable = false)
    private Boolean ignoreCase;

    /**
     * 是否忽略空格
     */
    @NotNull(message = "空格忽略设置不能为空")
    @Column(name = "ignore_whitespace", nullable = false)
    private Boolean ignoreWhitespace;

    /**
     * 是否忽略标点符号
     */
    @NotNull(message = "标点符号设置不能为空")
    @Column(name = "ignore_punctuation", nullable = false)
    private Boolean ignorePunctuation;

    /**
     * 最小匹配长度
     */
    @Column(name = "min_match_length")
    private Integer minMatchLength;

    /**
     * 最大匹配长度
     */
    @Column(name = "max_match_length")
    private Integer maxMatchLength;

    /**
     * 字符编码
     */
    @Size(max = 20, message = "字符编码长度不能超过20个字符")
    @Column(name = "character_encoding", length = 20)
    private String characterEncoding;

    /**
     * 答案状态（ACTIVE-激活，INACTIVE-非激活，DEPRECATED-已废弃）
     */
    @NotBlank(message = "答案状态不能为空")
    @Size(max = 20, message = "答案状态长度不能超过20个字符")
    @Column(name = "status", nullable = false, length = 20)
    private String status;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    private Integer usageCount;

    /**
     * 匹配成功次数
     */
    @Column(name = "match_count")
    private Integer matchCount;

    /**
     * 匹配成功率
     */
    @Column(name = "match_success_rate", precision = 5, scale = 4)
    private Double matchSuccessRate;

    /**
     * 平均匹配时间（毫秒）
     */
    @Column(name = "average_match_time_ms", precision = 8, scale = 2)
    private Double averageMatchTimeMs;

    /**
     * 置信度评分（0-1之间）
     */
    @Column(name = "confidence_score", precision = 3, scale = 2)
    private Double confidenceScore;

    /**
     * 难度系数（1-5分）
     */
    @Column(name = "difficulty_factor")
    private Integer difficultyFactor;

    /**
     * 知识点关联
     */
    @Column(name = "knowledge_points", columnDefinition = "TEXT")
    private String knowledgePoints;

    /**
     * 扩展属性（JSON格式）
     */
    @Column(name = "extended_properties", columnDefinition = "TEXT")
    private String extendedProperties;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新人ID
     */
    @Size(max = 50, message = "更新人ID长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 审核人ID
     */
    @Size(max = 50, message = "审核人ID长度不能超过50个字符")
    @Column(name = "reviewer_id", length = 50)
    private String reviewerId;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;
}